﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.LuFang.API.Application.Command.deepprocessingCommand;
using RBAC.LuFang.API.Dtos;
using RBAC.LuFang.Domain.Traceability;
using System.Collections.Generic;

namespace RBAC.LuFang.API.Controllers
{
    /// <summary>
    /// 深加工控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class deepprocessingController : ControllerBase
    {
        private readonly IMediator _mediator;

        public deepprocessingController(IMediator mediator)
        {
            _mediator = mediator;
        }


        /// <summary>
        /// 反填深加工
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<deepprocessing>> Getdeepprocessing(GetdeepprocessingCommand goodsid)
        {
            ApiResult<deepprocessing> result=new ApiResult<deepprocessing>();
            try
            {
                result.Data = await _mediator.Send(goodsid);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 更新深加工
        /// </summary>
        /// <param name="deepprocessing"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> Upddeepprocessing(UpddeepprocessingCommand deepprocessing)
        {
            ApiResult<int> result=new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(deepprocessing);
            }
            catch (Exception ee)
            {
                result.Code= -1;
                result.Message=ee.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 显示深加工
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<List<deepprocessing>>> Showdeepprocessing(ShowdeepprocessingCommand goodsid)
        {
            ApiResult<List<deepprocessing>> result = new ApiResult<List<deepprocessing>>();
            try
            {
                result.Data = await _mediator.Send(goodsid);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 删除食品安全信息
        /// </summary>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelfootPic(DelfootPicCommand goodsid)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(goodsid);  
            }
            catch (Exception ee)
            {
                result.Code=-1;
                result.Message=ee.Message;
                throw;
            }
            return result;
        }

        /// <summary>
        /// 显示食品安全信息
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<imges>>> ShowfootPic([FromQuery]ShowfootPicCommand showfoot)
        {
            ApiResult<List<imges>> result = new ApiResult<List<imges>>();
            try
            {
                result.Data = await _mediator.Send(showfoot);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示相关材料 原料
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<imges>>> GetXiangpic([FromQuery]GetXiangpicCommand getXiangpic)
        {
            ApiResult<List<imges>> result = new ApiResult<List<imges>>();
            try
            {
                result.Data = await _mediator.Send(getXiangpic);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 删除相关材料 原料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelXiangpic(DelXiangpicCommand id)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(id);
            }
            catch (Exception ee)
            {
                result.Code= -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示相关材料 辅料
        /// </summary>
        /// <param name="imgtype"></param>
        /// <param name="goodsid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<imges>>> GetXiangpicFu([FromQuery]GetXiangpicFuCommand getXiangpicFu)
        {
            ApiResult<List<imges>> result = new ApiResult<List<imges>>();
            try
            {
                result.Data = await _mediator.Send(getXiangpicFu);
            }
            catch (Exception ee)
            {
                result.Code=-1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 删除相关材料 辅料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelXiangpicFu(DelXiangpicFuCommand id)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data=await _mediator.Send(id);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }










    }
}
